package com.example.spring_leran1.utils;


import java.util.HashMap;
import java.util.Map;


public class Result {
    private Boolean success;
    private Integer code;
    private String msg;
    private Map<String, Object> data=new HashMap<>();

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {return data;}
    public void setData(Map<String, Object> data) {this.data=data;}

    private Result(){}
    //成功的方法
    public static Result ok(){
        Result r=new Result();
        r.setSuccess(true);
        r.setCode(20000);
        r.setMsg("成功");
        return r;
    }

    public static Result error(){
        Result r=new Result();
        r.setSuccess(false);
        r.setCode(20001);
        r.setMsg("失败");
        return r;
    }

    public Result data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
}
